package lily.phs.healthedu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import lily.phs.urh.R;

public class kaoqianfudao extends Activity {
	private Animation in_left;
	private Animation in_right;
	private Animation out_left;
	private Animation out_right;
	private TextView trainning_title;
	private TextView trainning_content;
	//private GridView gv;
	ListView listView;
	private String[] data1 = { "中医助理医师考试大纲《中药学》", "中医助理医师考试大纲《内科学》", "中医助理医师大纲《传染病学》",
			"中医助理医师大纲《卫生法规》", "中医助理医师考试大纲《针灸学》" };
	private String[] data2 = { "汤老师3.24访谈之医师第一阶段如何复习", "中医执业助理医师考试备考的提醒", "中医执业助理医师：看书务必要仔细",
			"通过中医助理医师考试的八点体会", "2011中医执业助理医师考试状态调整" };
	private String[] data3 = { "固涩剂的应用注意事项", "温里剂的应用注意事项", "清热剂的适用范围",
			"治风剂的使用注意事项", "开窍剂的应用注意事项" };
	Button leftBtn;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.trainning_kaoqianfudao);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.i_title);
        
        out_left = AnimationUtils.loadAnimation(this,R.anim.anim_slide_out_left);
        out_right = AnimationUtils.loadAnimation(this,R.anim.anim_slide_out_right);
        in_right = AnimationUtils.loadAnimation(this, R.anim.anim_slide_in_right);
        in_left = AnimationUtils.loadAnimation(this,R.anim.anim_slide_in_left);
        
        //TextView tv_TitleBar = (TextView)findViewById(R.id.tv_titlebar);     
        leftBtn = (Button) findViewById(R.id.title_left_btn);
        final Button rightBtn = (Button) findViewById(R.id.title_right_btn);
        final Button rightBtn2 = (Button) findViewById(R.id.title_right_btn2);
        leftBtn.setText("后退");
        leftBtn.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
				overridePendingTransition(R.anim.anim_slide_in_left,R.anim.anim_slide_out_right);
			}
        	
        });
        rightBtn.setVisibility(View.GONE);
        rightBtn2.setVisibility(View.GONE);
        listView = (ListView)this.findViewById(R.id.list);
        listView.setDivider(null);
        
    	Bundle bd = getIntent().getExtras();
    	final int child = bd.getInt("child");

    	switch(child)
    	{
    	case 0:
    		//tv_TitleBar.setText("职业助理医师考前辅导->考试大纲");
			listView.setAdapter(new SquareItemAdapter(this,data1));
			break;
    	case 1:
    		//tv_TitleBar.setText("职业助理医师考前辅导->考试经验");
			listView.setAdapter(new SquareItemAdapter(this,data2));
			break;
    	case 2:
    		//tv_TitleBar.setText("职业助理医师考前辅导->辅导精华");
			listView.setAdapter(new SquareItemAdapter(this,data3));
			break;
				
    	}
		listView.setOnItemClickListener(new OnItemClickListener() {  
			  
            @Override  
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,  
                    long arg3) {  
				Intent intent = new Intent(kaoqianfudao.this,kaoqianfudao_item.class);
				Bundle bundle = new Bundle();
				bundle.putInt("child", child);
				bundle.putInt("id", arg2);
				intent.putExtras(bundle);
				startActivity(intent);
				overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
            }  
        });  

		/*
		 * gv = (GridView)this.findViewById(R.id.menu); String[] menubar = new
		 * String[]{"首页", "后退", "帮助", "菜单" }; int[] menuIcon = new int[]{
		 * R.drawable.controlbar_homepage,
		 * R.drawable.controlbar_backward_enable, R.drawable.controlbar_window,
		 * R.drawable.controlbar_showtype_list, }; ArrayList<Map<String ,
		 * Object>> gv_array = new ArrayList<Map<String , Object>>(); for(int
		 * i=0;i<menubar.length;i++){ Map<String , Object> gv_item = new
		 * HashMap<String , Object>(); gv_item.put("menuIcon", menuIcon[i]);
		 * gv_item.put("menuOrder", menubar[i]);
		 * System.out.println("menuOrder="+menubar[i]); gv_array.add(gv_item);
		 * //System.out.println("gv_item="+gv_item.toString()); } SimpleAdapter
		 * gvAdapter = new SimpleAdapter(kaoqianfudao.this, gv_array,
		 * R.layout.griditem, new String[]{"menuIcon","menuOrder"}, new
		 * int[]{R.id.gv_icon,R.id.gv_text}); gv.setAdapter(gvAdapter);
		 * gv.setOnItemClickListener(new OnItemClickListener(){ public void
		 * onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) { //
		 * TODO Auto-generated method stub switch(arg2){ case 0:{//主界面
		 * startActivity(new Intent(kaoqianfudao.this,MainActivity.class));
		 * overridePendingTransition
		 * (R.anim.anim_slide_in_left,R.anim.anim_slide_out_right); finish();
		 * break; } case 1:{//back finish();
		 * overridePendingTransition(R.anim.anim_slide_in_left
		 * ,R.anim.anim_slide_out_right); break; } case 2:{//
		 * 
		 * break; } } }});
		 */

}
}

class SquareItemAdapter extends BaseAdapter{
	Context context;
	TextView tvName;
	String[] ItemNames;
	int count;

	public SquareItemAdapter(Context arg2,String[] ItemNames) {
		this.context = arg2;
		this.ItemNames = ItemNames;
	}

	@Override
	public int getCount(){
		return ItemNames.length;
	}

	@Override
	public Object getItem(int paramInt){
		return Integer.valueOf(paramInt);
	}

	@Override
	public long getItemId(int paramInt){
		return paramInt;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		// TODO Auto-generated method stub
			
		LayoutInflater factory = LayoutInflater.from(context);	
		View localView = factory.inflate(R.layout.square_item_view_trainning, null);
		
		ViewHolder mViewHolder = new ViewHolder();
		mViewHolder.tv = (TextView)localView.findViewById(R.id.tvItemName);
		ImageView iv=(ImageView)localView.findViewById(R.id.chufang_image);
		
		count = getCount();
		
		if (position == 0){//第一项
			String str1 = ItemNames[0];
			mViewHolder.tv.setText(str1);
			localView.setBackgroundResource(R.drawable.circle_list_top);
		}

		if (position> 0&position<count-1){
			String str2 = ItemNames[position];
			mViewHolder.tv.setText(str2);
			localView.setBackgroundResource(R.drawable.circle_list_middle);
		}
		
		if(position == count-1){
			String str3 = ItemNames[count-1];
			mViewHolder.tv.setText(str3);
			localView.setBackgroundResource(R.drawable.circle_list_bottom);	
		}

		return localView;
	
	}
}

class ViewHolder
{
	ImageView iv;
	TextView tv;

	ViewHolder()
	{
	}
}